A central goal of neuroscience is to understand relationships between the physical world, neural activity, and perception. Perception is not purely a product of the physical stimulus, but is strongly shaped by cognitive factors such as motivation, attention and expectations for sensory input. Touch perception depends in part on activity in the primary somatosensory cortex (S1). Here, tactile information arrives along neural pathways originating at sensory receptors in the skin, and is combined with ongoing brain activity that reflects the contributions of distinct types of neuron within S1, and long-range inpus from other brain areas. The resulting activity varies from one stimulus presentation to the next. Some but not all sensory cortex neurons show correlations between spiking and choices about sensory stimuli. What underlies this diversity in neural activity during behavior? The goal of this project is to elucidate cellular and circuit mechanisms that determine behavior-related variability in S1 activity patterns during a simple perceptual task. The results will uncover mechanisms to help explain the striking diversity of sensory responses observed in cortex during behavior, and to link cortical activity to perception. Mice perform a tactile detection task in which they make choice to indicate the presence or absence of a whisker deflection. Activity in multiple types of S1 neuron is related to the tactile stimulus and to behavioral choice. Manipulation of expectation for stimulus timing is used to investigate how cognitive state shapes activity in S1. Neural dynamics must be understood across multiple spatial and temporal scales. Here, activity is monitored and perturbed on scales ranging from intracellular membrane potential (millivolts over milliseconds in single neurons), to activity across neural circuits (>150 neurons over 0.5 mm). This is possible by combining behavior with intracellular electrophysiology, two-photon calcium imaging, and optogenetic stimulation. Experiments focus on layers (L) 4 and 2/3 of a single functional column of S1, whose basic architecture is preserved from mice to humans. L4 is the site of strongest input to cortex for touch information, but L4 neurons project axons only locally, essentially to the home cortical column. L4 powerfully excites L2/3 neurons, which project from S1 to downstream areas. L2/3 neurons receive prominent long-range input from higher brain areas, and may be a major site of behavior-related top-down modulation of sensory activity. This project tests multiple hypotheses to challenge the theory that trial-to-trial variability in L-L2/3 activity: (a) impacts perception, and (b) is shaped by behavior-dependent engagement of distinct neuron populations, whose regulation by internal brain state (c) increases as activity propagates from L4 to L2/3. The results will help provide mechanistic explanations for the diverse sensory cortex activity patterns underlying behavior. Understanding L4-L2/3 circuit dynamics may provide critical insight into how propagation of neural activity and sensory processing can be disrupted during disease.